package com.youle.robots.gateway.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

@Aspect
@Configuration
public class Authorize {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Value("${spring.profiles.active}")
    private String active;

    @Around("execution(* com.youle.robots.gateway.config.*.preHandle(..))")
    public Object around(ProceedingJoinPoint joinPoint) {
        Object result = true;
        if (StringUtils.isEmpty(active) || !"dev".equals(active)) {
            try {
                result = joinPoint.proceed();
            } catch (Throwable throwable) {
                logger.error(throwable.getMessage());
            }

        }
        return result;
    }
}
